// 设置存储信息
import storage from 'good-storage'
const OSS_KEY = '__oss_token__' // 阿里的token 登陆阿里账号的东西, web - 》 后段获取临时token
const OSS_ACCOUNT_KEY = '__oss_account__'// 程序传输用的
const PROGRESS_RECORD_SUCCESS_KEY = '__progress_record_success_token__' // 存储传序记录成功
const PROGRESS_RECORD_FAIL_KEY = '__progress_record_fail_token__' // 存储传序记录失败
const USER_NAME = '__user_name__'
const PASSWORD = '__password__'
const STATUS_MONITOR_DETAIL_TAB = '__status_monitor_detail_tab__'

// oss临时授权账号
export function saveOss (oss) {
  storage.set(OSS_KEY, oss)
  return oss
}
export function loadOss () {
  let oss = storage.get(OSS_KEY, '')
  return oss
}

export function saveOssAccount (ossAcount) {
  let ossAccount = storage.set(OSS_ACCOUNT_KEY, ossAcount)
  return ossAccount
}

export function loadOssAccount () {
  let ossAccount = storage.get(OSS_ACCOUNT_KEY, '')
  return ossAccount
}

export function removeOssAccount () {
  storage.remove(OSS_ACCOUNT_KEY)
}
// 传输成功记录
export function saveProgressSuccessRecord (userId, record) {
  storage.set(PROGRESS_RECORD_SUCCESS_KEY + userId, JSON.stringify(record))
  return record
}
export function loadProgressSuccessRecord (userId) {
  let record = storage.get(PROGRESS_RECORD_SUCCESS_KEY + userId, '')
  return record ? JSON.parse(record) : []
}
export function clearProgressSuccessRecord (userId, record) {
  storage.set(PROGRESS_RECORD_SUCCESS_KEY + userId, '')
  return record
}

// 传输失败记录
export function saveProgressFailRecord (userId, record) {
  storage.set(PROGRESS_RECORD_FAIL_KEY + userId, JSON.stringify(record))
  return record
}
export function loadProgressFailRecord (userId) {
  let record = storage.get(PROGRESS_RECORD_FAIL_KEY + userId, '')
  return record ? JSON.parse(record) : []
}
export function clearProgressFailRecord (userId, record) {
  storage.set(PROGRESS_RECORD_FAIL_KEY + userId, '')
  return record
}

// 账号密码
export function saveUserName (userName) {
  storage.set(USER_NAME, userName)
  return userName
}

export function loadUserName () {
  let userName = storage.get(USER_NAME, '')
  return userName
}

// 账号密码
export function savePassword (password) {
  storage.set(PASSWORD, password)
  return password
}

export function loadPassword () {
  let password = storage.get(PASSWORD, '')
  return password
}

/**
 * 设置状态监控机台列表详情当前的tab
 * @param tab
 * @returns {*}
 */
export function setStatusMonitorList (tab) {
  storage.set(STATUS_MONITOR_DETAIL_TAB, tab)
  return tab
}

/**
 * 获取状态监控机台列表详情当前的tab
 * @param tab
 * @returns {*}
 */
export function getStatusMonitorList () {
  return storage.get(STATUS_MONITOR_DETAIL_TAB)
}
